#pragma once

#include "reactor.hpp"
#include "event_handler.hpp"
#include <map>
#include <memory>

class Dispatcher
{
public:
    Dispatcher() = default;
    ~Dispatcher() = default;
    void AddConsumer(int fd, int event, EventHandler&& handler);
    void RmvConsumer(int fd);
    void Poll();
    void Break() { active = false; }
private:
    void Wakeup();
    bool active { true };
    Reactor reactor;
    std::map<int, EventHandler> handlerMap;
};

using DispatcherPtr = std::shared_ptr<Dispatcher>;